<template>
    <div class="login-container">
        <div>
            <el-form
                :model="ruleForm2"
                :rules="rules"
                ref="loginForm"
                status-icon
                label-width="100px"
                class="demo-ruleForm"
            >
                <el-form-item label="用户名" prop="username">
                    <el-input
                        prefix-icon="iconfont icon-user"
                        type="text"
                        v-model="ruleForm2.username"
                        auto-complete="off"
                    ></el-input>
                </el-form-item>
                <el-form-item label="确认密码" prop="password">
                    <el-input
                        prefix-icon="iconfont icon-user"
                        type="password"
                        v-model="ruleForm2.password"
                        auto-complete="off"
                    ></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">提交</el-button>
                    <el-button @click="resetForm">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
           
<script>
export default {
  data() {
    return {
      ruleForm2: {
        username: "admin",
        password: "123456"
      },
      rules: {
        username: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 15, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ],
        password: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 15, message: "长度在 3 到 5 个字符", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    submitForm() {
      this.$refs.loginForm.validate(async vv => {
        //console.log(vv,777);
        if (!vv) return;
        const { data: res } = await this.$http.post("login", this.ruleForm2);

        console.log(res);
        if (res.meta.status == 200) {
          this.$message({
            message: "恭喜你，这是一条成功消息",
            type: "success"
          });
        } else {
          this.$message({
            message: "登录失败",
            type: "warning"
          });
        }
      });
    },
    resetForm() {
      this.$refs.loginForm.resetFields();
    }
  }
};
</script>
<style scoped lang='less'>
.login-container {
  width: 600px;
  height: 400px;
  background-color: #fff;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
</style>